#include "adaptor_parm.h"
#include "main.h"
#include "operate_parm.h"

string str_ada;

struct adaptor_paramter_summary adaptor_parm;

void adaptor_data_update(void)
{
  QString qstring_tmp;
  float float_tmp;

  for (unsigned int i = 0; i < SLAVE_NUM; i++)
  {
    master_adaptor_parm_widget.slave_mount[i]->set_clicked((adaptor_parm.master_conctrller_ada_parm.mount_config & (1 << i)) ? (1) : (0));
  }
  master_adaptor_parm_widget.brake_enable->set_clicked(((adaptor_parm.master_conctrller_ada_parm.check_feature.bit.brake) ? (1) : (0)));
  master_adaptor_parm_widget.commander_comm_enable->set_clicked(((adaptor_parm.master_conctrller_ada_parm.check_feature.bit.brake) ? (1) : (0)));

  for (unsigned int i = 0; i < SLAVE_NUM; i++)
  {
    float_tmp = adaptor_parm.laser_ada_parm[i].level1_mo1 * 0.1;
    qstring_tmp.clear();
    qstring_tmp.setNum(float_tmp, 'f', 1);
    qstring_tmp += "A";
    adaptor_parm_summary[i].week1_mo1_current->set_text((char *)qstring_tmp.toStdString().c_str());

    float_tmp = adaptor_parm.laser_ada_parm[i].level1_mo2 * 0.1;
    qstring_tmp.clear();
    qstring_tmp.setNum(float_tmp, 'f', 1);
    qstring_tmp += "A";
    adaptor_parm_summary[i].week1_mo2_current->set_text((char *)qstring_tmp.toStdString().c_str());

    float_tmp = adaptor_parm.laser_ada_parm[i].level1_fa1 * 0.1;
    qstring_tmp.clear();
    qstring_tmp.setNum(float_tmp, 'f', 1);
    qstring_tmp += "A";
    adaptor_parm_summary[i].week1_fa1_current->set_text((char *)qstring_tmp.toStdString().c_str());

    float_tmp = adaptor_parm.laser_ada_parm[i].level1_fa2 * 0.1;
    qstring_tmp.clear();
    qstring_tmp.setNum(float_tmp, 'f', 1);
    qstring_tmp += "A";
    adaptor_parm_summary[i].week1_fa2_current->set_text((char *)qstring_tmp.toStdString().c_str());

    float_tmp = adaptor_parm.laser_ada_parm[i].level2_mo1 * 0.1;
    qstring_tmp.clear();
    qstring_tmp.setNum(float_tmp, 'f', 1);
    qstring_tmp += "A";
    adaptor_parm_summary[i].week2_mo1_current->set_text((char *)qstring_tmp.toStdString().c_str());

    float_tmp = adaptor_parm.laser_ada_parm[i].level2_mo2 * 0.1;
    qstring_tmp.clear();
    qstring_tmp.setNum(float_tmp, 'f', 1);
    qstring_tmp += "A";
    adaptor_parm_summary[i].week2_mo2_current->set_text((char *)qstring_tmp.toStdString().c_str());

    float_tmp = adaptor_parm.laser_ada_parm[i].level2_fa1 * 0.1;
    qstring_tmp.clear();
    qstring_tmp.setNum(float_tmp, 'f', 1);
    qstring_tmp += "A";
    adaptor_parm_summary[i].week2_fa1_current->set_text((char *)qstring_tmp.toStdString().c_str());

    float_tmp = adaptor_parm.laser_ada_parm[i].level2_fa2 * 0.1;
    qstring_tmp.clear();
    qstring_tmp.setNum(float_tmp, 'f', 1);
    qstring_tmp += "A";
    adaptor_parm_summary[i].week2_fa2_current->set_text((char *)qstring_tmp.toStdString().c_str());

    float_tmp = adaptor_parm.laser_ada_parm[i].strong_mo1 * 0.1;
    qstring_tmp.clear();
    qstring_tmp.setNum(float_tmp, 'f', 1);
    qstring_tmp += "A";
    adaptor_parm_summary[i].strong_mo1_current->set_text((char *)qstring_tmp.toStdString().c_str());

    float_tmp = adaptor_parm.laser_ada_parm[i].strong_mo2 * 0.1;
    qstring_tmp.clear();
    qstring_tmp.setNum(float_tmp, 'f', 1);
    qstring_tmp += "A";
    adaptor_parm_summary[i].strong_mo2_current->set_text((char *)qstring_tmp.toStdString().c_str());

    float_tmp = adaptor_parm.laser_ada_parm[i].strong_fa1 * 0.1;
    qstring_tmp.clear();
    qstring_tmp.setNum(float_tmp, 'f', 1);
    qstring_tmp += "A";
    adaptor_parm_summary[i].strong_fa1_current->set_text((char *)qstring_tmp.toStdString().c_str());

    float_tmp = adaptor_parm.laser_ada_parm[i].strong_fa2 * 0.1;
    qstring_tmp.clear();
    qstring_tmp.setNum(float_tmp, 'f', 1);
    qstring_tmp += "A";
    adaptor_parm_summary[i].strong_fa2_current->set_text((char *)qstring_tmp.toStdString().c_str());

    float_tmp = adaptor_parm.laser_ada_parm[i].strong_mo1 * 0.1;
    qstring_tmp.clear();
    qstring_tmp.setNum(float_tmp, 'f', 1);
    qstring_tmp += "A";
    adaptor_parm_summary[i].strong_mo1_current->set_text((char *)qstring_tmp.toStdString().c_str());

    float_tmp = adaptor_parm.laser_ada_parm[i].strong_mo2 * 0.1;
    qstring_tmp.clear();
    qstring_tmp.setNum(float_tmp, 'f', 1);
    qstring_tmp += "A";
    adaptor_parm_summary[i].strong_mo2_current->set_text((char *)qstring_tmp.toStdString().c_str());

    float_tmp = adaptor_parm.laser_ada_parm[i].strong_fa1 * 0.1;
    qstring_tmp.clear();
    qstring_tmp.setNum(float_tmp, 'f', 1);
    qstring_tmp += "A";
    adaptor_parm_summary[i].strong_fa1_current->set_text((char *)qstring_tmp.toStdString().c_str());

    float_tmp = adaptor_parm.laser_ada_parm[i].strong_fa2 * 0.1;
    qstring_tmp.clear();
    qstring_tmp.setNum(float_tmp, 'f', 1);
    qstring_tmp += "A";
    adaptor_parm_summary[i].strong_fa2_current->set_text((char *)qstring_tmp.toStdString().c_str());

    float_tmp = adaptor_parm.laser_ada_parm[i].mo1_up_limit * 0.1;
    qstring_tmp.clear();
    qstring_tmp.setNum(float_tmp, 'f', 1);
    qstring_tmp += "A";
    adaptor_parm_summary[i].mo1_current_over_limit->set_text((char *)qstring_tmp.toStdString().c_str());

    float_tmp = adaptor_parm.laser_ada_parm[i].mo2_up_limit * 0.1;
    qstring_tmp.clear();
    qstring_tmp.setNum(float_tmp, 'f', 1);
    qstring_tmp += "A";
    adaptor_parm_summary[i].mo2_current_over_limit->set_text((char *)qstring_tmp.toStdString().c_str());

    float_tmp = adaptor_parm.laser_ada_parm[i].fa_up_limit * 0.1;
    qstring_tmp.clear();
    qstring_tmp.setNum(float_tmp, 'f', 1);
    qstring_tmp += "A";
    adaptor_parm_summary[i].fa_current_over_limit->set_text((char *)qstring_tmp.toStdString().c_str());

    str_ada = to_string(adaptor_parm.laser_ada_parm[i].can_address);
    adaptor_parm_summary[i].can_address->set_text((char *)str_ada.c_str());

    str_ada = to_string(adaptor_parm.laser_ada_parm[i].pd1_low_limit * 20);
    str_ada += "mV";
    adaptor_parm_summary[i].pd1_low_limit->set_text((char *)str_ada.c_str());

    str_ada = to_string(adaptor_parm.laser_ada_parm[i].pd2_low_limit * 20);
    str_ada += "mV";
    adaptor_parm_summary[i].pd2_low_limit->set_text((char *)str_ada.c_str());

    str_ada = to_string(adaptor_parm.laser_ada_parm[i].pd3_low_limit * 20);
    str_ada += "mV";
    adaptor_parm_summary[i].pd3_low_limit->set_text((char *)str_ada.c_str());

    str_ada = to_string(adaptor_parm.laser_ada_parm[i].pd4_low_limit * 20) + "mV";
    adaptor_parm_summary[i].pd4_low_limit->set_text((char *)str_ada.c_str());

    float_tmp = adaptor_parm.laser_ada_parm[i].t1_low_limit * 0.1;
    qstring_tmp.clear();
    qstring_tmp.setNum(float_tmp, 'f', 1);
    qstring_tmp += "℃";
    adaptor_parm_summary[i].t1_low_limit->set_text((char *)qstring_tmp.toStdString().c_str());

    float_tmp = adaptor_parm.laser_ada_parm[i].t1_up_limit * 0.1;
    qstring_tmp.clear();
    qstring_tmp.setNum(float_tmp, 'f', 1);
    qstring_tmp += "℃";
    adaptor_parm_summary[i].t1_over_limit->set_text((char *)qstring_tmp.toStdString().c_str());

    float_tmp = adaptor_parm.laser_ada_parm[i].t2_low_limit * 0.1;
    qstring_tmp.clear();
    qstring_tmp.setNum(float_tmp, 'f', 1);
    qstring_tmp += "℃";
    adaptor_parm_summary[i].t2_low_limit->set_text((char *)qstring_tmp.toStdString().c_str());

    float_tmp = adaptor_parm.laser_ada_parm[i].t2_up_limit * 0.1;
    qstring_tmp.clear();
    qstring_tmp.setNum(float_tmp, 'f', 1);
    qstring_tmp += "℃";
    adaptor_parm_summary[i].t2_over_limit->set_text((char *)qstring_tmp.toStdString().c_str());

    float_tmp = adaptor_parm.laser_ada_parm[i].t3_low_limit * 0.1;
    qstring_tmp.clear();
    qstring_tmp.setNum(float_tmp, 'f', 1);
    qstring_tmp += "℃";
    adaptor_parm_summary[i].t3_low_limit->set_text((char *)qstring_tmp.toStdString().c_str());

    float_tmp = adaptor_parm.laser_ada_parm[i].t3_up_limit * 0.1;
    qstring_tmp.clear();
    qstring_tmp.setNum(float_tmp, 'f', 1);
    qstring_tmp += "℃";
    adaptor_parm_summary[i].t3_over_limit->set_text((char *)qstring_tmp.toStdString().c_str());

    float_tmp =((float) adaptor_parm.laser_ada_parm[i].t4_low_limit * 0.1);
    qstring_tmp.clear();
    qstring_tmp.setNum(float_tmp, 'f', 1);
    qstring_tmp += "℃";
    adaptor_parm_summary[i].t4_low_limit->set_text((char *)qstring_tmp.toStdString().c_str());

    float_tmp = adaptor_parm.laser_ada_parm[i].t4_up_limit * 0.1;
    qstring_tmp.clear();
    qstring_tmp.setNum(float_tmp, 'f', 1);
    qstring_tmp += "℃";
    adaptor_parm_summary[i].t4_over_limit->set_text((char *)qstring_tmp.toStdString().c_str());

    float_tmp = adaptor_parm.laser_ada_parm[i].envi_temperature_up_limit * 0.1;
    qstring_tmp.clear();
    qstring_tmp.setNum(float_tmp, 'f', 1);
    qstring_tmp += "℃";
    adaptor_parm_summary[i].envi_temperature_over_limit->set_text((char *)qstring_tmp.toStdString().c_str());

    float_tmp = (float)(adaptor_parm.laser_ada_parm[i].envi_temperature_low_limit * 0.1);
    qstring_tmp.clear();
    qstring_tmp.setNum(float_tmp, 'f', 1);
    qstring_tmp += "℃";
    adaptor_parm_summary[i].envi_temperature_low_limit->set_text((char *)qstring_tmp.toStdString().c_str());

    str_ada = to_string(adaptor_parm.laser_ada_parm[i].envi_humidity_up_limit);
    str_ada += "%";
    adaptor_parm_summary[i].envi_humidity_over_limit->set_text((char *)str_ada.c_str());

    str_ada = to_string(adaptor_parm.laser_ada_parm[i].wave_length);
    str_ada += "nm";
    adaptor_parm_summary[i].wave_length->set_text((char *)str_ada.c_str());
    
    str_ada = to_string(adaptor_parm.laser_ada_parm[i].expansion_module_id);
    adaptor_parm_summary[i].expansion_module_id->set_black_text((char *)str_ada.c_str());

    str_ada = to_string(adaptor_parm.laser_ada_parm[i].sn);
    adaptor_parm_summary[i].sn->set_text((char *)str_ada.c_str());

    adaptor_parm_summary[i].brake_enable->set_clicked((adaptor_parm.laser_ada_parm[i].check_feature_1.part.brake) ? (1) : (0));
    adaptor_parm_summary[i].power_comm_enable->set_clicked((adaptor_parm.laser_ada_parm[i].check_feature_1.part.power_comm) ? (1) : (0));
    adaptor_parm_summary[i].t1_enable->set_clicked((adaptor_parm.laser_ada_parm[i].check_feature_1.part.t1) ? (1) : (0));
    adaptor_parm_summary[i].t2_enable->set_clicked((adaptor_parm.laser_ada_parm[i].check_feature_1.part.t2) ? (1) : (0));
    adaptor_parm_summary[i].t3_enable->set_clicked((adaptor_parm.laser_ada_parm[i].check_feature_1.part.t3) ? (1) : (0));
    adaptor_parm_summary[i].t4_enable->set_clicked((adaptor_parm.laser_ada_parm[i].check_feature_1.part.t4) ? (1) : (0));
    adaptor_parm_summary[i].pd1_enable->set_clicked((adaptor_parm.laser_ada_parm[i].check_feature_1.part.pd1) ? (1) : (0));
    adaptor_parm_summary[i].pd2_enable->set_clicked((adaptor_parm.laser_ada_parm[i].check_feature_1.part.pd2) ? (1) : (0));

    adaptor_parm_summary[i].pd3_enable->set_clicked((adaptor_parm.laser_ada_parm[i].check_feature_2.part.pd3) ? (1) : (0));
    adaptor_parm_summary[i].pd4_enable->set_clicked((adaptor_parm.laser_ada_parm[i].check_feature_2.part.pd4) ? (1) : (0));
    adaptor_parm_summary[i].envi_temperature_enable->set_clicked((adaptor_parm.laser_ada_parm[i].check_feature_2.part.envi_temperature) ? (1) : (0));
    adaptor_parm_summary[i].envi_humidity_enable->set_clicked((adaptor_parm.laser_ada_parm[i].check_feature_2.part.envi_humidity) ? (1) : (0));
    adaptor_parm_summary[i].mo_current_enable->set_clicked((adaptor_parm.laser_ada_parm[i].check_feature_2.part.mo) ? (1) : (0));
    adaptor_parm_summary[i].fa_current_enable->set_clicked((adaptor_parm.laser_ada_parm[i].check_feature_2.part.fa) ? (1) : (0));
    adaptor_parm_summary[i].seq_enable->set_clicked((adaptor_parm.laser_ada_parm[i].check_feature_2.part.seq) ? (1) : (0));
    adaptor_parm_summary[i].master_comm_enable->set_clicked((adaptor_parm.laser_ada_parm[i].check_feature_2.part.master_comm) ? (1) : (0));
  }
}
